﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class BackPanel : MonoBehaviour
{
    public GameObject can;
    public Button ContinueButton;
    public Button QuXiaoButton;
    public GameObject gamepanel;
    public GameObject player;
    // Start is called before the first frame update
    void Start()
    {
        can = GameObject.Find("Canvas");
        gamepanel = GameObject.FindGameObjectWithTag("GamePanel");
        player = GameObject.Find("Player");
        ContinueButton.onClick.AddListener(OnClickContinnueButton);
        QuXiaoButton.onClick.AddListener(OnClickQuXiaoButton);
    }

  /// <summary>
  /// 点击继续按钮
  /// </summary>
    public void OnClickContinnueButton()
    {
        ShortVoice.instance.PlayVoice("AnNiu");
        DestroyImmediate(gameObject);
        DestroyImmediate(gamepanel);
        GameObject obj = Instantiate(Resources.Load<GameObject>("UIPanel/MainPanel"));
        obj.transform.SetParent(can.transform);
        obj.transform.localPosition = new Vector3(0, 0, 0);
        obj.transform.GetComponent<RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, 0, 0);
        obj.transform.GetComponent<RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, 0);
        obj.transform.GetComponent<RectTransform>().anchorMin = Vector2.zero;
        obj.transform.GetComponent<RectTransform>().anchorMax = Vector2.one;
        player.GetComponent<BoxCollider2D>().enabled = true;
 
    }
    /// <summary>
    /// 点击取消按钮
    /// </summary>
    public void OnClickQuXiaoButton()
    {
        ShortVoice.instance.PlayVoice("AnNiu");
        DestroyImmediate(gameObject);
        GamePanel.instance.IsDeath = false;
        GamePanel.instance.YiFuHuo = true;
        Player.instance.IsMove = false;
        GamePanel.instance.ZheZhao.gameObject.SetActive(false);
    }
}
